<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Proxy 与 Reflect</title>
</head>
<body>
  <script>
   const user = {
     name: 'tom',
     age: 12
   }

   // 创建一个代理对象
   const userProxy = new Proxy(user, {
     // 拦截读取属性
     get (target, property) {
       console.log(`拦截到读取${property}`)

      //  return target[property]
      return Reflect.get(target, property)
     },
     // 拦截设置属性值/添加新属性
     set (target, property, value) {
       console.log(`拦截到设置或添加属性`, property, value)

      //  return target[property]
      return Reflect.set (target, property, value)
     },

     // 拦截删除属性
     deleteProperty (target, property) {
       console.log(`拦截到删除属性`, property)

      //  return target[property]
      return Reflect.deleteProperty(target, property)
     },
   })

  //  console.log(userProxy.name)
  //  userProxy.name += '--'

  // 添加新属性
  // userProxy.sex = '女'
  // 删除已有属性
   delete userProxy.sex

   
  </script>
</body>
</html>